﻿
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using ProductionLine.Modules.ShareLib.Helpers;
using ProductionLine.Modules.ShareLib.Models;
using System.Threading.Tasks;

namespace ProductionLine.Modules.Params.ViewModels;

public partial class ParamsViewModel : ObservableObject {
    [ObservableProperty]
    private  GlobalConfig _globalConfig;

    [ObservableProperty]
    private PlcParam _plcParam;

    public ParamsViewModel( GlobalConfig globalConfig, PlcParam plcParam) {
        _plcParam = plcParam;
        GlobalConfig = globalConfig;
    }

    /// <summary>
    /// 自动采集操作
    /// </summary>
    [RelayCommand]
    async Task ToggleCollection() {
        if (PlcParam.AutoCollect) {//开启自动采集
            await GlobalConfig.StartCollectionAsync();//自动采集,为了防止重复采集，方法内部先停止了之前的采集
        } else {//关闭自动采集
            GlobalConfig.StopCollection();
        }
    }
    /// <summary>
    /// 自动模拟操作
    /// </summary>
    [RelayCommand]
    void ToggleMock() {
        if (PlcParam.AutoMock) {
            GlobalConfig.StartMockData();
        } else {
            GlobalConfig.StopMockData();
        }
    }



}